package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;
import android.util.Log;

import com.aishua.lib.task.AsResult;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.jsonbean.ResGetPersonalCenterBean;
import com.rjwh.dingdong.client.bean.localbean.BannerData;
import com.rjwh.dingdong.client.bean.localbean.GetPersonalCenterBean;
import com.rjwh.dingdong.client.bean.localbean.PersonalCenter;
import com.rjwh.dingdong.client.bean.localbean.PersonalCenterActivity;
import com.rjwh.dingdong.client.bean.localbean.PersonalCenterCell;
import com.rjwh.dingdong.client.bean.localbean.PersonalCenterMenuData;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.MorePersonalCenterModel;
import com.rjwh.dingdong.client.mvp.presenter.IMorePersonalCenterPresenter;
import com.rjwh.dingdong.client.mvp.view.MorePersonalCenterView;
import com.rjwh.dingdong.client.util.LogUtil;
import com.rjwh.dingdong.client.util.ToastUtil;

import java.util.List;

/**
 * @author Kay
 * @ClassName MorePersonalCenterPresenter
 * @Description
 * @date 2016-9-28
 * @history 2016-9-28 author: description:
 */

public class MorePersonalCenterPresenter extends BasePresenter<MorePersonalCenterView> implements IMorePersonalCenterPresenter {

    private MorePersonalCenterModel model;

    public MorePersonalCenterPresenter(Context context, MorePersonalCenterView mMvpView) {
        super(context, mMvpView);
        this.model = new MorePersonalCenterModel(this);
    }

    /**
     * 获取个人中心资料
     */
    @Override
    public void doGetPersonalCenter() {
        isViewAttached();
        getMvpView().hideErrorView();
//        getMvpView().showLoadingView();
        model.doGetPersonalCenter();
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (getMvpView() != null) {
            getMvpView().hideLoadingView();
            switch (businessType) {
                case NetConstant.GETPERSONALCENTER:
                    ResGetPersonalCenterBean resGetPersonalCenterBean = (ResGetPersonalCenterBean) mAsResult.getObj();
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS && resGetPersonalCenterBean != null && resGetPersonalCenterBean.getData() != null) {
                        getMvpView().hideErrorView();
                        GetPersonalCenterBean data = resGetPersonalCenterBean.getData();
                        PersonalCenter personalcenter = data.getPersonalcenter();
                        List<List<PersonalCenterMenuData>> cells = data.getCells();
                        List<BannerData> bannerlist = data.getBannerlist();
                        if (personalcenter != null && cells != null) {
                            getMvpView().loadData(personalcenter, cells);
                        }
                        if(bannerlist!=null){
                            getMvpView().laodBannerData(bannerlist);
                        }
                    } else {
                        getMvpView().loadLocalList();
                    }
                    break;
            }
        }
    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }


}
